#include "BigInteger.h"

#include <iostream>
#include <string>
#include <sstream>

namespace
  {
  std::string IntToStr(long long int i_a)
    {
    std::ostringstream ss;
    ss << i_a;
    return ss.str();
    }
  
  bool CheckPlus()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000, c = rand() - 16000;
        BigInteger A(a), B(b), C(c), D;
        D = A + B + C;
        if (IntToStr(a + b + c) != static_cast<std::string>(D)
            || IntToStr(a) != static_cast<std::string>(A)
            || IntToStr(b) != static_cast<std::string>(B)
            || IntToStr(c) != static_cast<std::string>(C))
          return false;
      }
    return true;
    }
  bool CheckMinus()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000;
        BigInteger A(a), B(b), C;
        C = A - B;
        if (IntToStr(a - b) != static_cast<std::string>(C)
            || IntToStr(a) != static_cast<std::string>(A)
            || IntToStr(b) != static_cast<std::string>(B))
          return false;
      }
    return true;
    }
  bool CheckMult()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000;
        BigInteger A(a), B(b), C;
        C = A * B;
        if (IntToStr(a * b) != static_cast<std::string>(C)
            || IntToStr(a) != static_cast<std::string>(A)
            || IntToStr(b) != static_cast<std::string>(B))
          return false;
      }
    return true;
    }
  bool CheckDiv()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000;
        BigInteger A(a), B(b), C;
        C = A / B;
        if (IntToStr(a / b) != static_cast<std::string>(C)
            || IntToStr(a) != static_cast<std::string>(A)
            || IntToStr(b) != static_cast<std::string>(B))
          return false;
      }
    return true;
    }
  bool CheckMod()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000;
        if (b == 0) continue;
        BigInteger A(a), B(b), C;
        C = A % B;
        if (IntToStr(a % b) != static_cast<std::string>(C)
            || IntToStr(a) != static_cast<std::string>(A)
            || IntToStr(b) != static_cast<std::string>(B))
          return false;
      }
    return true;
    }
  bool CheckLess()
    {
    for (int it = 0; it < 1000; ++it)
      {
        int a = rand() - 16000, b = rand() - 16000;
        BigInteger A(a), B(b);
        if ((a < b) != (A < B))
          return false;
      }
    return true;
    }
  }

int main()
  {
  try
    {
    std::cout << CheckPlus() << std::endl;
    std::cout << CheckMinus() << std::endl;
    std::cout << CheckMult() << std::endl;
    std::cout << CheckDiv() << std::endl;
    std::cout << CheckMod() << std::endl;
    std::cout << CheckLess() << std::endl;


    BigInteger a("-10000"), b("-12378");
    std::string s = --a;
    std::cout << s << std::endl;
    std::cout << static_cast<std::string>(a) <<std::endl;
    if (a < 0)
      {
      std::cout << "cool\n";
      }
    }
  catch(const std::string& i_e)
    {
    std::cout << i_e << std::endl;
    }
  return 0;
  }